Follow along – http://cpsievert.github.io/slides/web-pages

Why make a web page?

  • Because, internet!

Ain't nobody got time for that!

  • I know your busy, but web technologies are becoming more & more important for statistical computing:
    • Data "scraping", web APIs, etc.
    • Interactive graphics
    • Interactive reports/documents
    • Cloud computing
  • Even if none of this interests you, having a web presence is incredibly helpful in landing internships/jobs/etc.

University resources

GitHub

  • With a http://github.com account, anyone can create a nice looking website in minutes.
  • If you don't have a github account, please sign up now! All you need is a valid username/email/password.

What is GitHub?

  • A web-based hosting service for Git repositories (aka. Git repos).
  • Git is a popular version control system. A Git repo is a folder of files where changes can be easily logged and reversed.
  • Git is an essential tool for software developers and researchers concerned with reproducibility (it could also prove useful in tracking changes to your website).
  • You won't need to know Git to get a "Hello World!" version of your website, but trust me, learn it, it pays off.

GitHub Pages

  • GitHub also provides a service called GitHub Pages which essentially gives you a free domain name and hosting service.
  • There's (at least) two ways to serve files via GitHub Pages:

    1. Create the "special" username.github.io repository (where username is your GitHub username). I recommend using this repo for your personal website.
    2. Push to the "gh-pages" branch instead of the default "master" branch. Note this works for any repo.

Create a website on http://username.github.io

  • Click on Settings
  • Scroll down and click "Automatic Page Generator":

  • Choose a layout and "Publish Page"
  • Fist pump – you just made a website!!

'Clone' the repo to your machine

  • Open RStudio -> File -> New Project -> Version Control:

  • Choose git project
  • Paste the remote into the "Repository URL" field:

  • To make changes, you could hand edit the "index.html" file and push those changes back to GitHub and/or just start over.

A disclaimer

  • This "Automatic Page Generation" option is easy, but it might be too easy for some (hard to extend/customize).
  • Writing html is painful, which is why Markdown (a set of rules for producing HTML from plain text) was created.
  • If you want to keep a blog, you may want to consider learning about:
    1. Jekyll – a framework for creating websites/blogs from Markdown.
    2. knitr-jekyll – weave your R code/output into blog posts using R Markdown! (beware, Yihui has said this isn't quite ready)
  • This next approach to creating webpages is a bit more flexible in the sense that you have control over how html files are generated.

Using the gh-pages branch (demo)

  • Copy the remote

  • Open RStudio -> File -> New Project -> Version Control:

  • Choose git project:
  • Paste the remote into the "Repository URL" field:

  • File -> New File -> R Markdown:
  • File -> Save As. Name it "index.Rmd"

  • Click "Knit HTML" button:

  • Go to Start -> All Programs -> Git -> Git Bash.
  • Navigate to the my_project directory.

Push files to the special gh-pages branch

$ git branch
* master

$ git checkout -b gh-pages
Switched to a new branch 'gh-pages'

$ git branch
* gh-pages
  master
  
$ ls
index.Rmd         index.html        my_project.Rproj

$ git add *
$ git commit -m "Initial Commit"
$ git push origin gh-pages
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/cpsievert/my_project
 * [new branch]      gh-pages -> gh-pages

That's it, thanks for listening!

I'm glad to stick around and answer any questions…